import Router from "koa-router";
import bodyParser from "koa-bodyparser";
import controllersUrl from "./blogsControllers.js"
import cors from "@koa/cors"

let router= new Router()


export const useControllers= function(app){
    app.use(cors())

    app.use(bodyParser())
    controllersUrl.forEach(obj=>{
  
                    if(obj.method==="get"){
                        router.get(obj.url,obj.fn)
                    }
                    if(obj.method==="post"){
                        router.post(obj.url,obj.fn)
                    }
                    if(obj.method==="put"){
                        router.put(obj.url,obj.fn)
                    }
                    if(obj.method==="del"){
                        router.delete(obj.url,obj.fn)
                    }
                })
            
    app.use(router.routes())       
}